package com.dudu.log.ticketLog.action;

import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.dudu.bean.UserBean;
import com.dudu.log.ticketLog.service.ITicketService;
import com.dudu.log.ticketLog.service.impl.TicketServiceImpl;

import core.CoreService;

/**
 * 查询话单信息
 * @author jack
 *
 */
public class TicketAction extends CoreService implements ITicketAction {
	
	// 当前登陆用户
	private final String KEY_CURRENT_USER = "key_current_user";
	//状态查询service
	private ITicketService ticketService = new TicketServiceImpl(); 
	
	/**
	 * 查询话单，按分页条件查询
	 * @return
	 */
	public String queryAll() {
		log.info("TicketAction.queryAll");
		JSONObject object = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        //获取当前登录用户信息
        UserBean currentUser = (UserBean) this.getSession().getAttribute(KEY_CURRENT_USER);
        if (currentUser != null) {
        	//获取页面分页用信息
	        String pageSql = this.getPageSql();
	        //获取查询参数信息
	        String paramSql = this.convertParams();
	        // 总数量
	        int totalAcount = this.ticketService.getTotalAcount(paramSql);
	        List<JSONObject> list = this.ticketService.queryAll(paramSql, pageSql);
	        jsonArray = JSONArray.fromObject(list);
	        
	        JSONObject dataobject = new JSONObject();
	        object.put("flag", "000000");
	        object.put("desc", "success");
	        dataobject.put("totalItemNum", totalAcount);
	        dataobject.put("items", jsonArray);
	        object.put("data", dataobject);
        } else {
			object.put("flag", "100000");
		}
        return returnData(object.toString());
	}
	
}
